# @Author: Zhixuan.Wang
# @IDE: PyCharm
# @Project: multimodal
# @File: Get_Effect_Img.py
# @Time: 2025/11/7 15:12
# @Description: 根据Annotations文件夹获取有效图片

import os
import shutil

Annotation_Path = r"D:\LungCancer\VOCdevkit\VOC2012\Annotations"
Image_Path = r"D:\LungCancer\VOCdevkit\VOC2012\JPEGImages"
Taeget_Path = r"D:\LungCancer\VOCdevkit\VOC2012\EffectiveImage"

for xml_name in os.listdir(Annotation_Path):
    # 鲍洋洋001
    xml_name = os.path.splitext(xml_name)[0].split('_')[0]
    for img in os.listdir(Image_Path):
        # 鲍洋洋001
        img_name = os.path.splitext(img)[0].split('_')[0]
        if img_name == xml_name:
            # 得到单一病人的单一图片路径
            img_path = os.path.join(Image_Path, img)
            # 重塑该图片的名称
            new_img_name = img_name + '.jpg'
            # 指定存储路径
            target_path = os.path.join(Taeget_Path, new_img_name)
            # 将原路径下的图片复制到目标路径下
            shutil.copy2(img_path, target_path)

print("Over!")

